	clear all
	set more off

	
	use "$data/secondary/final_data.dta", clear

	merge 1:1 num_quest using "$data/choice_data.dta", keepusing(risk_*) keep(match)

	*********************************************************************
	***				ALTERNATIVE MEASURES OF RISK TOLERANCE 			  ***
	*********************************************************************
	
	*** COEFFICIENT of VARIATION of SELECTED OPTION 
		
	gen SD_EV1 = .
		replace SD_EV1 = 0 			if risk_G_J == 1  
		replace SD_EV1 = 2			if risk_G_J == 4
		replace SD_EV1 = 1			if risk_G_J == 15

	gen SD_EV2 = .
		replace SD_EV2 = 0			if risk_G_L == 1  
		replace SD_EV2 = 2			if risk_G_L == 6
		replace SD_EV2 = 1			if risk_G_L == 15
		
	gen SD_EV3 = .
		replace SD_EV3 = 0			if risk_H_J == 2	
		replace SD_EV3 = 2			if risk_H_J == 4
		replace SD_EV3 = 1			if risk_H_J == 15

	gen SD_EV4 = .
		replace SD_EV4 = 0			if risk_H_K == 2  	
		replace SD_EV4 = 9/7.5		if risk_H_K == 5
		replace SD_EV4 = 9/15		if risk_H_K == 15
		
	gen SD_EV5 = .
		replace SD_EV5 = 0			if risk_H_L == 2  	
		replace SD_EV5 = 2			if risk_H_L == 6
		replace SD_EV5 = 1			if risk_H_L == 15
		
	gen SD_EV6 = .
		replace SD_EV6 = 0			if risk_I_J == 3  	
		replace SD_EV6 = 2			if risk_I_J == 4
		replace SD_EV6 = 1			if risk_I_J == 15

	gen SD_EV7 = .
		replace SD_EV7 = 0			if risk_I_K == 3  	
		replace SD_EV7 = 9/7.5		if risk_I_K == 5
		replace SD_EV7 = 9/15		if risk_I_K == 15

	
	*** IF RISKY, DIFFERENCE in EXPECTED VALUE, DIVIDED by STANDARD DEVIATION of RISKY OPTION
 	*** IF RISKLESS, 0
	
	gen sharpe1 = .
		replace sharpe1 = 0 				if risk_G_J == 1 	
		replace sharpe1 = (7.5-3)/15		if risk_G_J == 4
		replace sharpe1 = (7.5-3)/30		if risk_G_J == 15

	gen sharpe2 = .
		replace sharpe2 = 0					if risk_G_L == 1 
		replace sharpe2 = (4.5 - 3)/9		if risk_G_L == 6
		replace sharpe2 = (4.5 - 3)/18		if risk_G_L == 15
		
	gen sharpe3 = .
		replace sharpe3 = 0				 	if risk_H_J == 2
		replace sharpe3 = (7.5 - 6)/15		if risk_H_J == 4
		replace sharpe3 = (7.5 - 6)/30		if risk_H_J == 15

	gen sharpe4 = .
		replace sharpe4 = 0 				if risk_H_K == 2  
		replace sharpe4 = (7.5 - 6)/9		if risk_H_K == 5
		replace sharpe4 = (7.5 - 6)/18		if risk_H_K == 15
		
	gen sharpe5 = .
		replace sharpe5 = 0					if risk_H_L == 2  	
		replace sharpe5 = (4.5 - 6)/9		if risk_H_L == 6
		replace sharpe5 = (4.5 - 6)/18		if risk_H_L == 15
		
	gen sharpe6 = .
		replace sharpe6 = 0				 	if risk_I_J == 3  
		replace sharpe6 = (7.5 - 9)/15		if risk_I_J == 4
		replace sharpe6 = (7.5 - 9)/30		if risk_I_J == 15

	gen sharpe7 = .
		replace sharpe7 = 0 				if risk_I_K == 3
		replace sharpe7 = (7.5 - 9)/9		if risk_I_K == 5
		replace sharpe7 = (7.5 - 9)/18		if risk_I_K == 15
		
		
	*** INDICATOR for CHOOSING RISKY OPTION
	
	gen risky1 = (risk_G_J == 4)	if risk_G_J < .

	gen risky2 = (risk_G_L == 6)	if risk_G_L < .
		
	gen risky3 = (risk_H_J == 4) 	if risk_H_J < .

	gen risky4 = (risk_H_K == 5) 	if risk_H_K < .
		
	gen risky5 = (risk_H_L == 6) 	if risk_H_L < .
		
	gen risky6 = (risk_I_J == 4)	if risk_I_J < .

	gen risky7 = (risk_I_K == 5) 	if risk_I_K < .

	
	******************************************************
	***		AVERAGING MEASURES across TRIALS 	   	   ***
	******************************************************
	
	egen risk_aversion2 = rowmean(SD_EV1 SD_EV2 SD_EV3 SD_EV4 SD_EV5 SD_EV6 SD_EV7)

	egen risk_aversion3 = rowmean(sharpe1 sharpe2 sharpe3 sharpe4 sharpe5 sharpe6 sharpe7)

	egen risk_aversion4 = rowmean(risky1 risky2 risky3 risky4 risky5 risky6 risky7)
	
	
	
	xtset cluster
	
	foreach var in risk_aversion risk_aversion2 risk_aversion3 risk_aversion4 {
		
		summ `var' if ITT == 0
		replace `var' = (`var'-r(mean))/r(sd)
			
		xtreg `var' male_ITT female_ITT male, r fe
			
	}
